package com.shawn.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shawn.dubbo.mapper.AnnouncementMapper;
import com.shawn.model.entity.Announcement;
import com.shawn.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class AnnouncementApiImpl implements AnnouncementApi{

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public PageResult<Announcement> getAnnouncementByPage(Integer page, Integer pageSize) {
        Page<Announcement> annPage = new Page<>(page, pageSize);
        LambdaQueryWrapper<Announcement> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByAsc(Announcement::getCreated);
        announcementMapper.selectPage(annPage,wrapper);
        return new PageResult<>(page,pageSize, (int) annPage.getTotal(),annPage.getRecords());
    }
}
